<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>v-for和v-if为什么不能连用？</title>
  </head>
  <body>
    <div id="app">
      <!-- v-for会比v-if优先执行 -->
      <div v-for="(color, index) in colors" v-if>
        <template v-if="index % 2">
          奇数 - {{ color }}
        </template>
        <template v-else>
          偶数 — {{ color }}
        </template>
      </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.min.js"></script>
    <script>
      new Vue({
        el: '#app',
        data() {
          return {
            colors: ['red', 'green', 'blue'],
            flag: true,
          };
        },
      });
    </script>
  </body>
</html>
